﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(Text))]
[ExecuteAlways]
public class TextAlign : MonoBehaviour
{
    Text m_textComponent;
    public TextAnchor OneLineAlignment;
    public TextAnchor MultiLineAlignment;

    // Start is called before the first frame update
    void Start()
    {
        m_textComponent = GetComponent<Text>();
    }

    // Update is called once per frame
    void Update()
    {
        if(m_textComponent.cachedTextGenerator.lineCount == 1)
        {
            m_textComponent.alignment = OneLineAlignment;
        }
        else
        {
            m_textComponent.alignment = MultiLineAlignment;
        }
    }
}
